/// Plot price variation and bundle discounts

********************************************************************************
*** Get data

use "data/pseudodata/userlevel_pseudodata.dta", clear

********************************************************************************
*** distributions of premia on price variation
assert !missing(totalagentpremium)
quietly summ totalagentpremium if price == "control"
local ncontrol = r(N)
quietly summ totalagentpremium if price == "low"
local nlow = r(N)
quietly summ totalagentpremium if price == "base"
local nbase = r(N)
quietly summ totalagentpremium if price == "high"
local nhigh = r(N)

quietly summ totalagentpremium if bundle == 0 & price!="control"
local nnobundle = r(N)
quietly summ totalagentpremium if bundle == 1 & price!="control"
local nbundle = r(N)

***3-month
local bw = 40
local lim = 500
twoway 	(kdensity totalagentpremium if price == "low" & totalagentpremium <= `lim', ///
			bwidth(`bw') lpattern(dash)) ///
		(kdensity totalagentpremium if price == "base" & totalagentpremium <= `lim', ///
			bwidth(`bw') lpattern(shortdash)) ///
		(kdensity totalagentpremium if price == "high" & totalagentpremium <= `lim', ///
			bwidth(`bw') lpattern(dash_dot)) ///
		(kdensity totalagentpremium if price == "control" & totalagentpremium <= `lim', ///
			bwidth(`bw') lpattern(solid) ///
			legend(size(med) bplacement(2) ring(0) label(4 "Control (N=`ncontrol')") ///
				label(1 "Low (N=`nlow')") ///
				label(2 "Base (N=`nbase')") label(3 "High (N=`nhigh')")) ///
			xtitle("3-month premium") ytitle("Density") ///
			title("(A)", bexpand j(left) size(medsmall)))
graph save one, replace
			
***daily
local bw = .6
local lim = 10
twoway 	(kdensity dayrate if price == "low" & dayrate <= `lim', ///
			bwidth(`bw') lpattern(solid)) ///
		(kdensity dayrate if price == "base" & dayrate <= `lim', ///
			bwidth(`bw') lpattern(dash)) ///
		(kdensity dayrate if price == "high" & dayrate <= `lim', ///
			bwidth(`bw') lpattern(shortdash) ///
			legend(size(med) bplacement(2) ring(0) label(1 "Low (N=`nlow')") ///
				label(2 "Base (N=`nbase')") label(3 "High (N=`nhigh')")) ///
			xtitle("Daily premium") ytitle("") ylabel(0(.1).3) ///
			title("(B)", bexpand j(left) size(medsmall)))
graph save two, replace


********************************************************************************
*** distributions of premia with and without bundle discount

gen dayrate_discounted = (24/30)*dayrate

***3-month
local bw = 40
local lim = 500
twoway 	(kdensity totalagentpremium if bundle == 0 & price!="control" & totalagentpremium <= `lim', ///
			bwidth(`bw') lpattern(dash)) ///
		(kdensity totalagentpremium if bundle == 1 & totalagentpremium <= `lim', ///
			bwidth(`bw') lpattern(shortdash)) ///
		(kdensity totalagentpremium if price == "control" & totalagentpremium <= `lim', ///
			bwidth(`bw') lpattern(solid) ///
			legend(size(med) bplacement(2) ring(0) label(3 "Control (N=`ncontrol')") ///
				label(1 "Pay-as-you-go," "no bundle (N=`nnobundle')") ///
				label(2 "Pay-as-you-go," "bundle (N=`nbundle')")) ///
			xtitle("3-month premium") ytitle("Density") ///
			title("(C)", bexpand j(left) size(medsmall)))
graph save three, replace
			
***daily

local bw = .6
local lim = 10
twoway 	(kdensity dayrate if bundle == 0 & dayrate <= `lim', ///
			bwidth(`bw') lpattern(solid)) ///
		(kdensity dayrate_discounted if bundle == 1 & dayrate <= `lim', ///
			bwidth(`bw') lpattern(dash) ///
			legend(size(med) bplacement(2) ring(0) ///
				label(1 "Pay-as-you-go," "no bundle (N=`nnobundle')") ///
				label(2 "Pay-as-you-go," "bundle (N=`nbundle')")) ///
			xtitle("Daily premium") ytitle("") ylabel(0(.1).3) ///
			title("(D)", bexpand j(left) size(medsmall)))
graph save four, replace

graph combine one.gph two.gph, cols(2) title("By price cohort", size(medsmall)) ///
	imargin(.01 .01 .01 .01)
graph save onethree, replace
graph combine three.gph four.gph, cols(2) title("By bundle discount offer", size(medsmall)) ///
	imargin(.01 .01 .01 .01)
graph save twofour, replace

graph combine onethree.gph twofour.gph, cols(1) iscale(0.8) imargin(1 .1 1 .1) xcommon
graph export "output/figures/experiment premium distributions.pdf", replace

erase one.gph
erase two.gph
erase three.gph
erase four.gph
erase onethree.gph 
erase twofour.gph

